#!/bin/bash
##################################################
#       Project: WGCNA enrich analysis
#       Date: Jun 28,2020
#       Author: Shawn Wang
##################################################
source ~/.bashrc
conda activate R
## Data structure
mkdir 01.GOEnrich 02.KEGGEnrich 03.Graph 04.Data 05.tmp
## make a Gene2module working file
cp *Gene2module.xls g2m.tmp
## split geneid by module names
m2gsplit $PWD
## GO enrichment and plot for top 30 terms
cd 01.GOEnrich && cp ../05.tmp/* ./ && ls * > config
## enrichment
for i in `cat config`; do TBgo --oboFile /public/home/wangxiao/03.MyScript/MyScript/TBtools/go-basic.obo --gene2GoFile /public/home/wangxiao/03.MyScript/MyScript/TBtools/CRI.TM1.V2.TBtools.gene2go --selectionSetFiles $i; done
## plot
GOplot $PWD
## KEGG enrichment and plot 
cd ../02.KEGGEnrich && cp ../05.tmp/* ./&& ls * >config
for i in `cat config`; do TBkegg --inKegRef /public/home/wangxiao/03.MyScript/MyScript/TBtools/TBtools.Plants.KEGG.Backend --Kannotation /public/home/wangxiao/03.MyScript/MyScript/TBtools/CRI.TM1.V2TBtools.gene2ko --selectedSet $i --outFile $i; done
    
KEGGplot $PWD
cd ../
mv *.pdf 03.Graph
mv *nwk *Rdata *xls 04.Data
